#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

void bucketSort(vector<int>& v)
{
    int max=*max_element(v.begin(),v.end());
    cout<<"Enter the number of buckets:"<<endl;
    int n;
    cin>>n;
    vector<vector<int>> buckets(n);
    //桶与数之间的函数映射关系 0-max/(n-1)*1, max/(n-1)+1-max/(n-1)*2
    for(int i=0;i<v.size();i++)
    {
        int no = v[i]/max*(n-1);
        buckets[no].push_back(v[i]);
    }
    for(int i=0;i<n;i++)
    {
        sort(buckets[i].begin(), buckets[i].end());
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<buckets[i].size();j++)
        {
            v.push_back(buckets[i][j]);
        }
    }
}
int main()
{
    cout<<"Enter the numbers:"<<endl;
    vector<int> v;
    int n;
    while(n!=-1)
    {
        cin>>n;
        v.push_back(n);
    }
    v.pop_back();
    bucketSort(v);
    cout<<"Sorted array:"<<endl;
    for(int i=v.size()/2;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}